//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Parsing
{
    /// <summary>
    /// Summary description for CharTypeManager.
    /// </summary>
        class CharTypeManager
        {

            public static bool IsBlank(char c)
            {
                switch (c)
                {
                    case ' ':
                    case '\n':
                    case '\t':
                    case '\r': return true;
                }
                return false;
            }
            public static bool IsAlphaNumOrColon(char c)
            {
                return c == ':' || IsAlphaNum_(c);
            }
            public static bool IsAlphaNum_(char c)
            {
                switch (c)
                {
                    case 'a':
                    case 'b':
                    case 'c':
                    case 'd':
                    case 'e':
                    case 'f':
                    case 'g':
                    case 'h':
                    case 'i':
                    case 'j':
                    case 'k':
                    case 'l':
                    case 'm':
                    case 'n':
                    case 'o':
                    case 'p':
                    case 'q':
                    case 'r':
                    case 's':
                    case 't':
                    case 'u':
                    case 'v':
                    case 'w':
                    case 'x':
                    case 'y':
                    case 'z':
                    case 'A':
                    case 'B':
                    case 'C':
                    case 'D':
                    case 'E':
                    case 'F':
                    case 'G':
                    case 'H':
                    case 'I':
                    case 'J':
                    case 'K':
                    case 'L':
                    case 'M':
                    case 'N':
                    case 'O':
                    case 'P':
                    case 'Q':
                    case 'R':
                    case 'S':
                    case 'T':
                    case 'U':
                    case 'V':
                    case 'W':
                    case 'X':
                    case 'Y':
                    case 'Z':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    case '0':
                    case '_':
                        return true;
                }
                return char.IsLetter(c);
            }
            /*[XCSharp.Attributes.CheckNamingRules(Enabled = false)]
            public static bool IsAlphaNum_Dot (char c)
            {
                switch (c)
                {
                    case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
                    case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': 
                    case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0':
                    case '_': case '.':
                        return true;
                }
                return char.IsLetter(c);
                //return false;
            }*/
            public static char[] Alpha_()
            {
                return new char[]
				{
					'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
					'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
					'_'
				};

            }
            public static char[] NumericsDot()
            {
                return new char[]{
									 '0', '1', '2','3','4','5','6','7','8','9', '.'
								 };
            }
            public static bool IsNumeric(char c)
            {
                switch (c)
                {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        return true;

                }
                return false;
            }
            public static bool IsHexa(char c)
            {
                switch (c)
                {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    case 'a':
                    case 'A':
                    case 'b':
                    case 'B':
                    case 'c':
                    case 'C':
                    case 'd':
                    case 'D':
                    case 'e':
                    case 'E':
                    case 'f':
                    case 'F':
                        return true;

                }
                return false;
            }
            public static int HexadecimalValue(char c)
            {
                if (!IsHexa(c))
                    Contract.Assert(IsHexa(c), "invalid hexadecimal character: " + c + "(" + (int)c + ")");
                switch (c)
                {
                    case '0': return 0;
                    case '1': return 1;
                    case '2': return 2;
                    case '3': return 3;
                    case '4': return 4;
                    case '5': return 5;
                    case '6': return 6;
                    case '7': return 7;
                    case '8': return 8;
                    case '9': return 9;
                    case 'a': return 10;
                    case 'A': return 10;
                    case 'b': return 11;
                    case 'B': return 11;
                    case 'c': return 12;
                    case 'C': return 12;
                    case 'd': return 13;
                    case 'D': return 13;
                    case 'e': return 14;
                    case 'E': return 14;
                    case 'f': return 15;
                    case 'F': return 15;
                }
                throw new Exception();
            }

            private static bool IsAlphaNumOrDotOrQuestionOrPercent(char c)
            {
                return c == '?' || c == '%' || c == '.' || IsAlphaNum_(c);
            }
            internal static bool IsAlphaNumOrDotOrQuestion(char c)
            {
                return c == '?' ||  c == '.' || IsAlphaNum_(c);
            }
        }
    }

